﻿set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
"behave xterm
behave mswin

function! MySys()
    return "windows"
endfunction

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700

" Enable filetype plugin
filetype plugin on
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","

" Fast saving
nmap <leader>w :w!<cr>

" Fast editing of the .vimrc
map <leader>e :tabedit! $VIM/_vimrc<cr>
map <leader>s :so $VIM/_vimrc<cr>

" When vimrc is edited, reload it
autocmd! bufwritepost _vimrc source $VIM/_vimrc

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
set so=7

set wildmenu "Turn on WiLd menu

set ruler "Always show current position

set cmdheight=2 "The commandbar height

set hid "Change buffer - without saving

" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

set ignorecase "Ignore case when searching
set smartcase

set hlsearch "Highlight search things

set incsearch "Make search act like search in modern browsers
set nolazyredraw "Don't redraw while executing macros 

set magic "Set magic on, for regular expressions

set showmatch "Show matching bracets when text indicator is over them
set mat=2 "How many tenths of a second to blink

" No sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable "Enable syntax hl

" Set font according to system
if MySys() == "mac"
  set gfn=Menlo:h14
  set shell=/bin/bash
elseif MySys() == "windows"
  "set gfn=Bitstream\ Vera\ Sans\ Mono:h10
elseif MySys() == "linux"
  set gfn=Monospace\ 10
  set shell=/bin/bash
endif

if has("gui_running")
  set guioptions-=T
  set t_Co=256
  set background=dark
  colorscheme torte
  set nonu
else
  colorscheme zellner
  set background=dark
  
  set nonu
endif

"Omni menu colors
hi Pmenu guibg=#444444
hi PmenuSel ctermfg=7 ctermbg=4 guibg=#555555 guifg=#ffffff

if MySys() == "windows"
  set encoding=cp936
else
  set encoding=utf8
endif
set fileencodings=utf8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
"set termencoding=utf8

set ffs=unix,dos,mac "Default file types

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile

"Persistent undo
try
    if MySys() == "windows"
      set undodir=C:\Windows\Temp
    else
      set undodir=~/.vim_runtime/undodir
    endif
    
    set undofile
catch
endtry

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab
set shiftwidth=4
set tabstop=8
set softtabstop=4
set smarttab

set lbr
set tw=500

set ai "Auto indent
set si "Smart indet
set wrap "Wrap lines

""""""""""""""""""""""""""""""
" => Taglist plugin
""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = 'ctags'
let Tlist_Show_One_File = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_Use_Right_Window = 0
map <silent><F9> :TlistToggle<cr>

""""""""""""""""""""""""""""""
" => Minibuffer plugin
""""""""""""""""""""""""""""""
"let g:miniBufExplMapWindowNavVim = 1
"let g:miniBufExplMapWindowNavArrows = 1
"let g:miniBufExplMapCTabSwitchBufs = 1
"let g:miniBufExplModSelTarget = 1 
""let g:miniBufExplorerMoreThanOne = 2
""let g:miniBufExplModSelTarget = 0
""let g:miniBufExplUseSingleClick = 1
""let g:miniBufExplVSplit = 25
""let g:miniBufExplSplitBelow=1
""let g:bufExplorerSortBy = "name"
"autocmd BufRead,BufNew :call UMiniBufExplorer
"map <leader>u :TMiniBufExplorer<cr>

""""""""""""""""""""""""""""""
" => omnicppcompl plugin
""""""""""""""""""""""""""""""
augroup CppProgs
    " configure tags - add additional tags here or comment out not-used ones
    autocmd FileType c,cpp set tags+=D:/tags/qt_tags
    "set tags+=D:/tags/boost_tags
    "set tags+=~/.vim/tags/cpp
    "set tags+=~/.vim/tags/gl
    "set tags+=~/.vim/tags/sdl
    "set tags+=~/.vim/tags/qt4
    " build tags of your own project with Ctrl-F12
    autocmd FileType cpp map <C-F12> :!ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
    " OmniCppComplete
    let OmniCpp_NamespaceSearch = 1
    let OmniCpp_GlobalScopeSearch = 1
    let OmniCpp_ShowAccess = 1
    let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
    let OmniCpp_MayCompleteDot = 1 " autocomplete after .
    let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
    let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
    let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
    " automatically open and close the popup menu / preview window
    au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
    set completeopt=menuone,menu,longest,preview
augroup END

""""""""""""""""""""""""""""""
" => echofunc plugin
""""""""""""""""""""""""""""""
let g:EchoFuncLangsUsed = ["java","cpp","python"]

""""""""""""""""""""""""""""""
" => doxygenToolkit plugin
""""""""""""""""""""""""""""""
let g:doxygenToolkit_authorName="nelson"
let g:doxygenToolkit_briefTag_funcName="yes"

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Nav for windows
noremap <C-H> <C-W>h
noremap <C-J> <C-W>j
noremap <C-K> <C-W>k
noremap <C-l> <C-W>l
" Nav for tabs
noremap <C-Tab> :tabnext<cr>
noremap <C-S-Tab> :tabprevious<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Protobuf
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup ProtobugProgs
    au! BufRead,BufNewFile *.proto setfiletype proto
augroup end

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Python
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup PythonProgs
    autocmd FileType python set omnifunc=pythoncomplete#Complete
    autocmd FileType python map <C-F12> :!ctags -R --sort=yes --python-kinds=+i .<CR>
    let g:pydoc_cmd="python D:/Python27/Tools/scripts/pydoc"
augroup END
